﻿/* Author:
 *  Andrea Russino
 */ 

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;

namespace TripLOAMobile.InternalEntities
{
    /// <summary>
    /// An instance of this class is a container for the login credentials.
    /// This class is local to the Mobile client of TripLOA and stores only the credentials
    /// entered by the user (no information sent by the central system.
    /// This class keep the path of the avatar and the avatarof the current user.
    /// </summary>
    public class Credentials
    {
        public string m_username;
        public string m_password;
        public string m_pathAvatar;
        private Image avatar;
        public int m_id; //The unique ID of the user inside the system. It is optional, could be useful for caching purposes.
        private bool useTriploaAnimationTheme=true;
        private string language;

        public List<WS_SoapLogin.VehicleInfo> listOfVeichles;//public solo per serializzarli??
        public List<WS_SoapLogin.UserInfo> buddyList;

        public string listVehiclesMD5,buddyListMD5;//public solo per serializzarli??

        /// <summary>
        /// Gets the MD5 of the list of vehicles cached.
        /// </summary>
        /// <value>The MD5 of the list of vehicles.</value>
        public string ListVehiclesMD5
        {
            get
            {
                if (listOfVeichles == null)
                    return null;
                return listVehiclesMD5;
            }
        }

        /// <summary>
        /// Gets the MD5 of the list of friends.
        /// </summary>
        /// <value>The MD5 of the list of friends.</value>
        public string BuddyListMD5
        {
            get
            {
                if (buddyList == null)
                    return null;
                return buddyListMD5;
            }
        }

        /// <summary>
        /// Sets the list of vehicles.
        /// </summary>
        /// <param name="wsuv">An object that contains the MD5 of the list and the list.</param>
        public void setListOfVehicles(WS_SoapLogin.WSUserVehicle wsuv)
        {
            if (wsuv.Status == RemoteResourceProvider.okStatus)
            {
                listVehiclesMD5 = wsuv.Hash;
                listOfVeichles = wsuv.Payload.ToList();
            }
        }

        /// <summary>
        /// Sets the buddy list.
        /// </summary>
        /// <param name="wsuser">An object that contains the MD5 of the list and the list.</param>
        public void setBuddyList(WS_SoapLogin.WSUser wsuser)
        {
            if (wsuser.Status == "ok")
            {
                buddyListMD5 = wsuser.BuddyListHash;
                buddyList = wsuser.Payload.ToList();
            }
        }

        /// <summary>
        /// Gets the list of veichles.
        /// </summary>
        /// <value>The list of veichles.</value>
        public List<WS_SoapLogin.VehicleInfo> ListOfVeichles
        {
            get
            {
                return listOfVeichles;
            }
        }

        /// <summary>
        /// Gets the buddy list.
        /// </summary>
        /// <value>The buddy list.</value>
        public List<WS_SoapLogin.UserInfo> BuddyList
        {
            get
            {
                return buddyList;
            }
        }

        /// <summary>
        /// Gets or sets the language.
        /// </summary>
        /// <value>The language.</value>
        public string Language
        {
            get
            {
                return language;
            }
            set
            {
                language = value;
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [use triploa animation theme].
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [use triploa animation theme]; otherwise, <c>false</c>.
        /// </value>
        public bool UseTriploaAnimationTheme
        {
            get
            {
                return useTriploaAnimationTheme;
            }
            set
            {
                useTriploaAnimationTheme = value;
            }
        }

        /// <summary>
        /// Sets the animation theme.
        /// </summary>
        /// <param name="useTriploaMobileTheme">if set to <c>true</c> [use triploa mobile theme].</param>
        public void setAnimationTheme(bool useTriploaMobileTheme)
        {
            this.useTriploaAnimationTheme = useTriploaMobileTheme;
        }


        /// <summary>
        /// Gets the avatar.
        /// </summary>
        /// <value>The avatar.</value>
        public Image Avatar
        {
            get
            {
                //if the path of the avatar is setted, but the image is not loade, then load it...
                if ((avatar == null) && (m_pathAvatar != null))
                    avatar = new Bitmap(m_pathAvatar);
                return avatar;
            }
        }

        /// <summary>
        /// Sets the local path of the avatar.
        /// </summary>
        /// <value>The path avatar.</value>
        public string PathAvatar
        {
            set
            {
                m_pathAvatar = value;
                if(value!=null)
                    avatar = new Bitmap(m_pathAvatar);
            }
        }

        public static Type getType()
        {
            return new Credentials("fake", "fake").GetType();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Credentials"/> class.
        /// </summary>
        /// <param name="username">The username.</param>
        internal Credentials(string username) : this(username,null) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="Credentials"/> class.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="password">The password.</param>
        internal Credentials(string username, string password)
        {
            m_username = username;
            m_password = password;
            m_pathAvatar = null;
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="Credentials"/> class.
        /// //Just for serialization
        /// </summary>
        internal Credentials() { }

        /// <summary>
        /// Gets the username.
        /// </summary>
        /// <value>The username.</value>
        internal string Username {
            get
            {
                return m_username;
            }
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        internal string Password { 
            get { return m_password; } 
            set { m_password = value; } 
        }

        /// <summary>
        /// Get or set the unique ID of the user inside the system for caching purposes.
        /// </summary>
        internal int ID
        {
            get { return m_id; }
            set { m_id = value; }
        }
    }
}
